layui.use(['form', 'layer','jquery','tree','util','laydate','upload'], function() {
    $ = layui.jquery;
    var form = layui.form,
    layer = layui.layer,
    upload = layui.upload,
    tree = layui.tree,
    util = layui.util,
    laydate = layui.laydate,
    ctx = $("#baseurl").val();

    //年选择器type: 'year','date','datetime'
    laydate.render({
        elem: '#year'
        ,type: 'year'
    });

    //监听提交
    form.on('submit(add)', function(data) {
        // data.field.classifyId = JSON.stringify(classifyIds.getValue());
        $.ajax({
        url: ctx+"/choujiang/luck_draw/add",
        data: data.field,
        type: 'post',
        success: function (data) {
            //发异步，把数据提交给php
            layer.alert("增加成功", {icon: 6},function () {
                //关闭当前frame
                xadmin.close();
                // 可以对父窗口进行刷新
                xadmin.father_reload();
            });
                //return false;
            }
        });
    });

    //头像上传
    var uploadInst = upload.render({
        elem: '#titleimg' //绑定元素
        ,url: ctx+'/file/fileOneAdd/' //上传接口
        ,accept: 'file'
        ,data: {busid:'',type:''}
        ,done: function(res){
            //上传完毕回调
            var data = res.data;
            $("#courseImg").val(data.httpUrl);
        }
        ,error: function(){
            //请求异常回调
        }
    });

    //问卷上传
    var uploadInst1 = upload.render({
        elem: '#wenjuan' //绑定元素
        ,url: ctx+'/file/fileOneAdd/' //上传接口
        ,accept: 'file'
        ,data: {busid:'',type:''}
        ,done: function(res){
            //上传完毕回调
            var data = res.data;
            $("#questionnaier_name").val(data.fileName);
            $("#questionnaier").val(data.fileId);
        }
        ,error: function(){
            //请求异常回调
        }
    });

});
